package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    OrderService orderService;



    /**
     * 各个状态的订单数量统计
     * @param
     * @return
     */
    @GetMapping("/statistics")
    public Result statistics(){
        log.info("各个状态的订单数量统计 ");
        OrderStatisticsVO result = orderService.statistics();
        return Result.success(result);
    }
    /**
     * 订单搜索
     * @param dto
     * @return
     */
    @GetMapping("/conditionSearch")
    public Result conditionSearch(OrdersPageQueryDTO dto){
        log.info("订单搜索 {}",dto);
        PageResult result  = orderService.conditionSearch(dto);
        return Result.success(result);
    }

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    public Result details(@PathVariable Long id){
        log.info("查询订单详情 {}",id);
        OrderVO orderVO = orderService.orderDetail(id);
        return Result.success(orderVO);
    }


    /**
     * 接单
     * @return
     */
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO dto){
        log.info("接单");
       orderService.confirm(dto);
        return Result.success();
    }


    /**
     * 拒单
     * @return
     */
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO dto){
        log.info("拒单");
        orderService.rejection(dto);
        return Result.success();
    }


    /**
     * 取消订单
     * @return
     */
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO dto){
        log.info("拒单");
        orderService.adminCancel(dto);
        return Result.success();
    }

    /**
     * 派送订单
     * @return
     */
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id){
        log.info("派送订单 {}",id);
        orderService.delivery(id);
        return Result.success();
    }


    /**
     * 完成订单
     * @return
     */
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id){
        log.info("完成订单 {}",id);
        orderService.complete(id);
        return Result.success();
    }
}
